<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/12
 * Time: 13:14
 */

namespace api\flower\model;
use think\Model;
use api\flower\model\FlowerFlowertypeModel;
class FlowerFlowerinfoModel extends Model
{
    /**
     * dottime读取器
     * 在查询的时候将时间戳转换成时间格式
     */
    protected function getDottimeAttr($dottime){
        if(!empty($dottime)){
            return date('Y-m-d H:i:s',$dottime);
        }else{
            return $dottime;
        }
    }

    /**
     *
     * status状态
     * 在查询的时候将状态换成‘热销’还是‘普通’
     */
    protected function getStatusAttr($status){
          if($status==1){
               return '热销';
          }else{
              return '普通';
          }
    }
    /**
     * Imgs鲜花展示图片
     */
    protected function getImgsAttr($imgs){
        if(!empty($imgs)){
            $imgs = stripslashes($imgs);//addslashes(json_encode($data['imgs']));
            $imgs = json_decode($imgs);
            $data = [];

            foreach($imgs as $k=>$v){
                if($_SERVER['HTTP_HOST']=='localhost'){
                    $data[$k] = cmf_get_image_url($v);
                }else{
                    //$data[$k] = 'http://'.$_SERVER['HTTP_HOST'].'/'.cmf_get_image_url($v);
                    $data[$k] = cmf_get_image_url($v);
                }

            }
            return $data;
        }else{
            return $imgs;
        }
    }
    /**
     * 鲜花的类型
     */
    protected function getTypeidAttr($typeid){
       // $type = new FlowerFlowertypeModel();
       // $res = $type->get($typeid);
       /* if(!empty($res)){
            return $res['name'];
        }else{*/
            return $typeid;
        //}
    }

    /**
     * @param $coverimg
     * 拼接图片地址
     */
    protected function getCoverimgAttr($coverimg){
        if(!empty($coverimg)){
            if($_SERVER['HTTP_HOST']=='localhost'){
                $coverimg = cmf_get_image_url($coverimg);
            }else{
               // $coverimg = 'http://'.$_SERVER['HTTP_HOST'].'/'.cmf_get_image_url($coverimg);
                $coverimg = cmf_get_image_url($coverimg);
            }
            return $coverimg;
        }else{
            return $coverimg;
        }
    }

}